﻿<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>
	
				<article>
					<h2>Duomenys apie nuteistąjį</h2>
	<?php 
	if (!isset($_GET['userid'])) {
		$to = "client.php";
		redirect_to($to);
		echo "asshole";
			exit;  
	};
	//Query is user table
	$query = "SELECT *";
	$query .= " FROM `user`, `lovos`";
	$query .= " WHERE `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	//$query .= " AND `lovos`.`lovosid` = `user`.`lovosid`";
	//$query .= " AND (`foto`.`userid` = `user`.`userid` AND `foto`.`pagrindine` = 1)";
	//echo $query."</br>";
	$result_set = mysql_query($query, $connection);

	$client = mysql_fetch_array($result_set);
	//print_r ($client) ;

	//query is lovos table
	$query = "SELECT *";
	$query .= " FROM `user`, `lovos`";
	$query .= " WHERE";
	$query .= "`lovos`.`lovosid` = `user`.`lovosid`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	//$query .= " AND `lovos`.`lovosid` = `user`.`lovosid`";
	//$query .= " AND (`foto`.`userid` = `user`.`userid` AND `foto`.`pagrindine` = 1)";
	//echo $query."</br>";
	$result_set = mysql_query($query, $connection);
	
	$vieta = mysql_fetch_array($result_set);
	
	$foto = NULL;
	//Query is foto table
	$query = "SELECT `foto`.path ";
	$query .= " FROM `foto`";
	$query .= " WHERE `foto`.`userid` =";
	$query .= "'".$_GET['userid']."'";
	//$query .= " AND `lovos`.`lovosid` = `user`.`lovosid`";
	$query .= " AND `foto`.`pagrindine` = 1";
	//echo $query."</br>";
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$foto = mysql_fetch_array($result_set);
		if(isset($foto['path'])){
			$foto_path = $foto['path'];
		} else {$foto_path = "images/idiot.png";
		};
	};
	
	//query is pilietybes table
	$query = "SELECT *";
	$query .= " FROM `user`, `pilietybe`";
	$query .= " WHERE";
	$query .= "`user`.`pilietybeid` = `pilietybe`.`pilietybeid`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	//$query .= " AND `lovos`.`lovosid` = `user`.`lovosid`";
	//$query .= " AND (`foto`.`userid` = `user`.`userid` AND `foto`.`pagrindine` = 1)";
	//echo $query."</br>";
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$pil = mysql_fetch_array($result_set);
	};
	
	
	//query is nuobaudos table
	$query = "SELECT *";
	$query .= " FROM `nuobaudos`,`nuobaudosrusys`,`pazeidimurusys`";
	$query .= " WHERE";
	$query .= " `nuobaudos`.`userid` =";
	$query .= "'".$_GET['userid']."'";
	$query .= " AND `nuobaudos`.`nuobrusysid`=";
	$query .= " `nuobaudosrusys`.`nuobrusysid`";
	$query .= " AND `nuobaudos`.`pazeidrusysid`=";
	$query .= " `pazeidimurusys`.`pazeidrusysid`";
	$query .= " ORDER BY `nuobaudos`.`svarstdata` ASC";
	$nuobaudos_set = mysql_query($query, $connection);
	confirm_query($nuobaudos_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		};
	
	//query is paskatinimai table
	$query = "SELECT *";
	$query .= " FROM `paskatinimai`,`paskatinimorusys`,`paskatinimopriezastys`";
	$query .= " WHERE";
	$query .= " `paskatinimai`.`userid` =";
	$query .= "'".$_GET['userid']."'";
	$query .= " AND `paskatinimai`.`paskrusysid`=";
	$query .= " `paskatinimorusys`.`paskrusysid`";
	$query .= " AND `paskatinimai`.`paskrusysid`!=";
	$query .= " 17";
	$query .= " AND `paskatinimai`.`paskrusysid`!=";
	$query .= " 18";
	$query .= " AND `paskatinimai`.`paskatinimopriezastysid`=";
	$query .= " `paskatinimopriezastys`.`paskatinimopriezastysid`";
	$query .= " ORDER BY `paskatinimai`.`svarstdata` ASC";
	$paskatinimai_set = mysql_query($query, $connection);
	confirm_query($paskatinimai_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		};
	
	//query is paskatinimai table 94
	$query = "SELECT *";
	$query .= " FROM `paskatinimai`,`paskatinimorusys`,`paskatinimopriezastys`";
	$query .= " WHERE";
	$query .= " `paskatinimai`.`userid` =";
	$query .= "'".$_GET['userid']."'";
	$query .= " AND `paskatinimai`.`paskrusysid`=";
	$query .= " `paskatinimorusys`.`paskrusysid`";
	$query .= " AND `paskatinimai`.`paskrusysid` IN";
	$query .= " (17, 18)";
	// $query .= " AND `paskatinimai`.`paskrusysid`=";
	// $query .= " 18";
	$query .= " AND `paskatinimai`.`paskatinimopriezastysid`=";
	$query .= " `paskatinimopriezastys`.`paskatinimopriezastysid`";
	$query .= " ORDER BY `paskatinimai`.`svarstdata` ASC";
	
	$soc_set = mysql_query($query, $connection);
	confirm_query($soc_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		};
	
	
	
		//query is tautybes table
	$query = "SELECT *";
	$query .= " FROM `user`, `tautybe`";
	$query .= " WHERE";
	$query .= "`user`.`tautybeid` = `tautybe`.`tautybeid`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	//$query .= " AND `lovos`.`lovosid` = `user`.`lovosid`";
	//$query .= " AND (`foto`.`userid` = `user`.`userid` AND `foto`.`pagrindine` = 1)";
	//echo $query."</br>";
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$tau = mysql_fetch_array($result_set);
		};
	
			//query is issilavinimo table
	$query = "SELECT *";
	$query .= " FROM `user`, `issilavinimas`";
	$query .= " WHERE";
	$query .= "`user`.`IssilavID` = `issilavinimas`.`IssilavID`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$iss = mysql_fetch_array($result_set);
		};
	
			//query is miestai table
	$query = "SELECT *";
	$query .= " FROM `user`, `miestai`, `rajonai`, `valstybes` ";
	$query .= " WHERE";
	$query .= "`user`.`gimmiestasid` = `miestai`.`miestaiid`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	$query .= " AND";
	$query .= " `miestai`.rajonaiid = `rajonai`.rajonaiid";
	$query .= " AND";
	$query .= " `miestai`.valstybesid = `valstybes`.valstybesid";
	
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$miest = mysql_fetch_array($result_set);
		};
	
		//query is miestai table
	$query = "SELECT *";
	$query .= " FROM `user`, `miestai`, `rajonai`, `valstybes` ";
	$query .= " WHERE";
	$query .= "`user`.`gyvmiestasid` = `miestai`.`miestaiid`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	$query .= " AND";
	$query .= " `miestai`.rajonaiid = `rajonai`.rajonaiid";
	$query .= " AND";
	$query .= " `miestai`.valstybesid = `valstybes`.valstybesid";
	
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$gyv = mysql_fetch_array($result_set);
		};
		
		//query is pareigos table
	$query = "SELECT *";
	$query .= " FROM `user`, `pareigos` ";
	$query .= " WHERE";
	$query .= "`user`.`pareigosid` = `pareigos`.`pareigosid`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$pareig = mysql_fetch_array($result_set);
		};
	
	
	//query is seimpad table
	$query = "SELECT *";
	$query .= " FROM `user`, `seimyninepadetis` ";
	$query .= " WHERE";
	$query .= "`user`.`SeimPadID` = `seimyninepadetis`.`SeimPadID`";
	$query .= " AND";
	$query .= " `user`.userid =";
	$query .= "'".$_GET['userid']."'";

	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$seimpad = mysql_fetch_array($result_set);
		};
		
		//query is bausme table
	$query = "SELECT *";
	$query .= " FROM `bausme` ";
	$query .= " WHERE";
	//$query .= "`user`.`SeimPadID` = `seimyninepadetis`.`SeimPadID`";
	//$query .= " AND";
	$query .= " `bausme`.userid =";
	$query .= "'".$_GET['userid']."'";

	$result_set = mysql_query($query, $connection);
	confirm_query($result_set); 
		if (!$result_set) {
			die("Database query failed: " . mysql_error());
		} else {
	$bausme = mysql_fetch_array($result_set);
		};
	
	
	?>
    

<table width="730" border="0" cellspacing="2" cellpadding="3">
  <tr>
    <td width="99">Bylos Nr.:</td>
    <td width="129"><strong><?php echo $client['bylosnr'];?></strong></td>
    <td width="100"><a href="naujas_klientas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td width="71">&nbsp;</td>
    <td width="289" rowspan="12" align="center"><a href="photo_upload.php?userid=<?php echo($_GET['userid']);?>" ><img src="<?php echo $foto_path;?>" alt="" width="200"  /></a>&nbsp;</td>
  </tr>
  <tr>
    <td>Vardas:</td>
    <td><strong><?php echo $client['vardas'];?></strong></td>
    <td><a href="naujas_klientas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>  
    <td>Pavardė:</td>
    <td><strong><?php echo $client['pavarde'];?></strong></td>
    <td><a href="naujas_klientas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Tėvavardis:</td>
    <td><strong><?php echo $client['tevavardis'];?></strong></td>
    <td><a href="naujas_klientas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Gimimo data:</td>
    <td><strong><?php echo $client['gimimodata'];?></strong></td>
    <td><a href="naujas_klientas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Asmens kodas:</td>
    <td><strong><?php echo $client['ak'];?></strong></td>
    <td><a href="naujas_klientas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Burys:</td>
    <td><strong><?php echo $vieta['burys'];?></strong></td>
    <td><a href="edit_burys.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Brigada:</td>
    <td><strong><?php echo $vieta['brigada'];?></strong></td>
    <td><a href="edit_burys.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Lova:</td>
    <td><strong><?php echo $vieta['lova'];?></strong></td>
    <td><a href="edit_burys.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Pilietybe</td>
    <td><strong>
     <?php echo $pil['Pilietybe'];?>
    </strong></td>
    <td><a href="tautybe.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Tautybe</td>
    <td><strong>
	<?php echo $tau['tautybe'];?>
	</strong></td>
    <td><a href="tautybe.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Išsilavinimas</td>
    <td><strong>
	<?php echo $iss['Issilav'];?>
	</strong></td>
    <td><a href="issilav.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    </tr>
  <tr>
    <td>Gimimo miestas</td>
    <td><strong><?php echo($miest['miestai']) . ", " . ($miest['rajonai']) . ", " . ($miest['valstybes']); ?></strong></td>
    <td><a href="miestas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Gyvenantis</td>
    <td><strong><?php echo($client['adresas']).", ".($gyv['miestai']) . ", " . ($gyv['rajonai']) . ", " . ($gyv['valstybes']); ?></strong></td>
    <td><a href="adresas.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Darboviete iki sulaikymo</td>
    <td><strong><?php echo($client['DarboVietaIki']); ?></strong></td>
    <td><a href="darbas_iki.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Pareigos</td>
    <td><strong><?php echo($pareig['pareigos']); ?></strong></td>
    <td><a href="darbas_iki.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Seimynine padetis</td>
    <td><strong><?php echo($seimpad['SeimPad']); ?></strong></td>
    <td><a href="seima.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Bausmes pradzia</td>
    <td><strong><?php echo($bausme['pradzia']); ?></strong></td>
    <td><a href="bausme.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Bausmes pabaiga</td>
    <td><strong><?php echo($bausme['pabaiga']); ?></strong></td>
    <td><a href="bausme.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Bausmes trukme</td>
    <td><strong><?php if ($bausme['paskmet']!=0){echo($bausme['paskmet'])." m.";};
					  if ($bausme['paskmen']!=0){echo($bausme['paskmen'])." men.";};
					  if ($bausme['paskdien']!=0){echo($bausme['paskdien'])." d.";};
	?></strong></td>
    <td><a href="bausme.php?userid=<?php echo($_GET['userid']);?>" title="Redaguoti">Redaguoti</a></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<p>Nuobaudos: </p> 
<table width="" border="1">
  <tr>
    <th>Eil.Nr.</th>
	<th>Kada</th>
    <th>Uz ka</th>
    <th>kokia</th>
  </tr>
  
 <?php $num=1;
 while ($row_result = mysql_fetch_assoc($nuobaudos_set)) {


 echo "<tr>";
 echo "<td align=\"center\">";
 echo $num++;
 echo "</td>";
 echo "<td>";
 echo $row_result['svarstdata'];
 echo "</td>";
 echo "<td>";
 echo $row_result['pazeidrusys'];
 echo "</td>";
 echo "<td>";
 echo $row_result['nutarta']." ";
 
 
 //bi
						if (($row_result['nuobrusysid']) == 4){
							if(($row_result['kiekisdien']) != 0){
								echo $row_result['kiekisdien'];
								if(($row_result['kiekisdien']) == 1){
								echo " parai.";}
								elseif((($row_result['kiekisdien']) > 1)AND(($row_result['kiekisdien'])) < 10){
								echo " parom.";}
								else{
								echo " parų.";};
							}elseif(($row_result['kiekismen']!= 0)){
								echo $row_result['kiekismen'];
								echo " mėn.";
							};
						};	
						//KTP
						if (($row_result['nuobrusysid']) == 5){
							if(($row_result['kiekisdien']) != 0){
								echo $row_result['kiekisdien'];
								echo " parų.";
							}elseif(($row_result['kiekismen']!= 0)){
								echo $row_result['kiekismen'];
								echo " mėn.";
							};
						};	
						
						//uola
						if (($row_result['nuobrusysid']) == 7){
							if(($row_result['kiekisdien']) != 0){
								echo $row_result['kiekisdien'];
								echo " parų.";
							}elseif(($row_result['kiekismen']!= 0)){
								echo $row_result['kiekismen'];
								echo " mėn.";
							};
						};	
						
						//laras
						if (($row_result['nuobrusysid']) == 3){
							if(($row_result['kiekisdien']) != 0){
								echo $row_result['kiekisdien'];
								echo " parų.";
							}elseif(($row_result['kiekismen']!= 0)){
								echo $row_result['kiekismen'];
								echo " mėn.";
							};
						};	
 
 
 
 
 echo "</td>";
 echo "</tr>";
}; 
 ?>
 </table>
 
 
  <br>
  <p>Paskatinimai: </p> 
<table width="" border="1">
  <tr>
    <th>Eil.Nr.</th>
    <th>Kada</th>
    <th>Uz ka</th>
    <th>koks</th>
  </tr>
  
 <?php $num = 1;
 while ($row_result = mysql_fetch_assoc($paskatinimai_set)) {
 echo "<tr>";
 echo "<td align=\"center\">";
 echo $num++;
 echo "</td>";
 echo "<td>";
 echo $row_result['svarstdata'];
 echo "</td>";
 echo "<td>";
 echo $row_result['paskatinimopriezastys'];
 echo "</td>";
 echo "<td>";
 if ($row_result['paskrusysid'] == 6){
	if ($row_result['nuobaudosid'] == NULL){
		echo $row_result['nutarta'];
	} else {	
		$query = "SELECT *";
		$query .= " FROM `nuobaudos`";
		$query .= " WHERE";
		$query .= "`nuobaudosid`=";
		$query .= $row_result['nuobaudosid'];
		$query .= " LIMIT 1";
		$result_set = mysql_query($query, $connection);
		confirm_query($result_set); 
			if (!$result_set) {
				die("Database query failed: " . mysql_error());
			} else {
		$n = mysql_fetch_array($result_set);};
		echo str_replace("%data%", $n['svarstdata'], $row_result['nutarta']);
	};
 } ELSE {
	echo $row_result['nutarta'];
 };
 echo "</td>";
 echo "</tr>";
};
  ?>
  
</table>
<br>
  <p>94 str.: </p> 
<table width="" border="1">
  <tr>
    <th>Eil.Nr.</th>
    <th>Kada</th>
    <th>Uz ka</th>
    <th>koks</th>
  </tr>
  
 <?php $num = 1;
 while ($row_result = mysql_fetch_assoc($soc_set)) {
 echo "<tr>";
 echo "<td align=\"center\">";
 echo $num++;
 echo "</td>";
 echo "<td>";
 echo $row_result['svarstdata'];
 echo "</td>";
 echo "<td>";
 echo $row_result['paskatinimopriezastys'];
 echo "</td>";
 echo "<td>";
 echo $row_result['nutarta'];
 echo "</td>";
 echo "</tr>";
};
  ?>
  
</table>
<p>&nbsp;</p>
        </article>
            
<?php require("includes/footer.php"); ?>
